import peewee
import datetime



db = peewee.SqliteDatabase('Bot.db')

class BaseModel(peewee.Model):
    class Meta:
        database = db

class User(BaseModel):
    wx_num = peewee.CharField(verbose_name='微信账户', unique=True)
    name = peewee.CharField(verbose_name='微信昵称')
    duihuacishu = peewee.IntegerField(verbose_name='对话次数', default=5)

class Bot(BaseModel):
    creattime = peewee.DateTimeField(verbose_name='创建时间', default=str(datetime.datetime.now()))
    user = peewee.ForeignKeyField(User, backref='bot')


class DuihuaList(BaseModel):
    botid = peewee.ForeignKeyField(Bot, backref='duihualist')
    userid = peewee.ForeignKeyField(User, backref='duihualist')


class Duihua(BaseModel):
    role = peewee.CharField(verbose_name='角色')
    time = peewee.DateTimeField(verbose_name='消息时间', default=str(datetime.datetime.now()))
    botid = peewee.ForeignKeyField(Bot, backref='duihua')
    userid = peewee.ForeignKeyField(User, backref='duihua')
    info = peewee.TextField(verbose_name='消息内容')
    duihualist = peewee.ForeignKeyField(DuihuaList, backref='duihua')




db.connect()

db.create_tables([User, Bot, DuihuaList, Duihua])